using System;
using System.Collections.Generic;

using Csla;

using EntModApp.EntServices.Business;

using DemoApp.DataAccess;

namespace DemoApp.BusinessLayer 
{
  public partial class CslaFavoriteDerivedInfo : 
    CslaFavoriteInfo, 
    IFavoriteDerived
  {
    #region [ Business Properties ]

    public static PropertyInfo<DateTime?> DateOfCreationPropertyInfo = RegisterProperty(new PropertyInfo<DateTime?>("DateOfCreation"));
    public DateTime? DateOfCreation 
    { 
      get
      {
        return ReadProperty(DateOfCreationPropertyInfo);
      }
      private set
      {
        LoadProperty(DateOfCreationPropertyInfo, value);
      }
    }

    public static PropertyInfo<CslaFavoriteInfoCollection> SubFavoritesPropertyInfo = RegisterProperty(new PropertyInfo<CslaFavoriteInfoCollection>("SubFavorites"));
    public CslaFavoriteInfoCollection SubFavorites 
    { 
      get
      {
        return ReadProperty(SubFavoritesPropertyInfo);
      }
      private set
      {
        LoadProperty(SubFavoritesPropertyInfo, value);
      }
    }

    #endregion [ Business Properties ]

    #region [ Factory Methods ]
    protected internal static CslaFavoriteDerivedInfo GetFavoriteDerivedInfo(FavoriteDerived data, FavoriteDerivedLoadSettings loadSettings)
    {
      if (data == null) throw new ArgumentNullException("data");
      if (loadSettings == null) throw new ArgumentNullException("loadSettings");
      CslaFavoriteDerivedInfo result = new CslaFavoriteDerivedInfo();
      result.FetchFavoriteDerived(data, loadSettings);
      return result;
    }

    private static int ForceInitField = 0;
    protected CslaFavoriteDerivedInfo() 
    {
      ForceInitField = 1;
    }
    #endregion [ Factory Methods ]

    #region [ Data Access ]
    protected void FetchFavoriteDerived(FavoriteDerived data, FavoriteDerivedLoadSettings loadSettings)
    {
      FetchFavoriteDerivedData(data, loadSettings);
      FetchFavoriteDerivedChildren(data, loadSettings);
    }

    protected void FetchFavoriteDerivedData(FavoriteDerived data, FavoriteDerivedLoadSettings loadSettings)
    {
      base.FetchFavoriteData(data, loadSettings);
      this.DateOfCreation = data.DateOfCreation;
    }

    protected void FetchFavoriteDerivedChildren(FavoriteDerived data, FavoriteDerivedLoadSettings loadSettings)
    {
      base.FetchFavoriteData(data, loadSettings);
      if (loadSettings.Inclusion.IncludeSubFavorites)
        this.SubFavorites = CslaFavoriteInfoCollection.GetFavoriteInfoCollection(data.SubFavorites, loadSettings.Inclusion.IncludedSubFavoritesSettings);
    }
    #endregion [ Data Access ]

    #region [ Explicit IFavoriteDerived implementation ]

    DateTime? IFavoriteDerived.DateOfCreation
    {
      get { return this.DateOfCreation; }
      set
      {
        throw new NotSupportedException();
      }
    }

    IBusinessObjectCollection<IFavorite> IFavoriteDerived.SubFavorites
    { 
      get
      {
        return this.SubFavorites;
      }
    }


    bool IBusinessObject.IsReadonly
    {
      get { return true; }
    }

    bool IBusinessObject.IsDirty
    {
      get { return false; }
    }

    #endregion [ Explicit IFavoriteDerived implementation ]
  }
}
